import request from '@/utils/request'
// // 获取图形验证码
// export const getPicCode = () => {
//   return request.get('/captcha/image', { platform: 'H5' })
// }
// export const getPicCode = (code) => {
//   return request.get(`/captcha/getPicCode/${encodeURIComponent(code)}`)
// }

// 获取短信验证码
export const getMsgCode = (mobile) => {
  return request.get('/user/getNoteCode', { params: { phone: mobile } })
}

// 验证码登陆接口
export const codeLogin = (mobile, msgCode) => {
  const formData = new FormData()
  formData.append('phone', mobile)
  formData.append('verificationCode', msgCode)
  formData.append('loginType', 'phone')

  return request({
    url: '/login',
    method: 'POST',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 密码登录
export const passwordLogin = (mobile, password) => {
  const formData = new FormData()
  formData.append('username', mobile)
  formData.append('password', password)
  formData.append('loginType', 'username')

  return request({
    url: '/login',
    method: 'POST',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 退出登录
export const logout = () => {
  return request.get('/logout')
}

// 判断是否登录
export const isLogin = () => {
  return request.get('/user/isLogin', {
    credentials: 'include' // 携带 Cookie
  })
}
